package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.excel.ExcelUtil;
import com.gfxy.modules.items.entity.Zyyxsztsjh;
import com.gfxy.modules.items.mapper.ZyyxsztsjhMapper;
import com.gfxy.modules.items.service.IZyyxsztsjhService;
import com.gfxy.modules.items.vo.JndsMemberPage;
import com.gfxy.modules.items.vo.ZyyxsztsjhMemberPage;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 职业院校素质提升计划
 * @Author: jeecg-boot
 * @Date:   2023-12-19
 * @Version: V1.0
 */
@Service
public class ZyyxsztsjhServiceImpl extends AbstractProjectServiceImpl<ZyyxsztsjhMapper, Zyyxsztsjh> implements IZyyxsztsjhService {

	protected int memberCellNum = 3;
	@Override
	public Double getTotalScore(Zyyxsztsjh zyyxsztsjh) {
		Integer level = zyyxsztsjh.getLevel();
		double result = 0;
		if(level == 1){
			result = 150;
		} else if (level == 2){
			result = 100;
		}
		return result;
	}

	@Override
	public IPage<ZyyxsztsjhMemberPage> selectListPage(String date, Integer pageNo, Integer pageSize) {
		Page<ZyyxsztsjhMemberPage> page = new Page<>(pageNo, pageSize);
		Page<ZyyxsztsjhMemberPage> page1 = page.setRecords(baseMapper.selectMemberPageListByYear(date));
		return page1;
	}

	@Override
	public List<ZyyxsztsjhMemberPage> getMemberPageListByYear(String date) {
		return baseMapper.selectMemberPageListByYear(date);
	}


	@Override
	protected Zyyxsztsjh getOneProject(Row row) {
		String year = ExcelUtil.formatCell(row.getCell(0));
		String levelStr = ExcelUtil.formatCell(row.getCell(1));
		String projectName = ExcelUtil.formatCell(row.getCell(2));
		Zyyxsztsjh zyyxsztsjh = new Zyyxsztsjh();
		zyyxsztsjh.setDate(year);
		zyyxsztsjh.setLevel(this.translateLevel(levelStr));
		zyyxsztsjh.setProjectName(projectName);
		zyyxsztsjh.setTotalScore(this.getTotalScore(zyyxsztsjh));

		return zyyxsztsjh;
	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	private Integer translateLevel(String levelStr) {
		if(levelStr == null || levelStr.equals("")){
			return 0;
		} else if(levelStr.equals("国家级(示范项目)")){
			return 1;
		} else if(levelStr.equals("国家级")){
			return 2;
		}else {
			return 0;
		}
	}
}
